<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="会议名称" prop="meetingName">
        <el-input
          v-model="queryParams.meetingName"
          placeholder="请输入会议名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="daterangeScheduleTime">
        <el-date-picker
          v-model="daterangeScheduleTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['condition:ours:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="oursList">
      <el-table-column type="index" width="55" align="center" label="序号"/>
      <el-table-column label="会议名称" align="center" prop="meetingName"/>
      <el-table-column label="密码" align="center" prop="password"/>
      <el-table-column label="会议开始时间" align="center" prop="startTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="邀请总人数" align="center" prop="totalInvites"/>
      <el-table-column label="拒绝人数" align="center" prop="rejectedCount"/>
      <el-table-column label="已签到人数" align="center" prop="attendedCount"/>
      <el-table-column label="发起时间" align="center" prop="meetingLaunchDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.meetingLaunchDate, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{
              scope.row.endTime == null ? '会议尚未开始' : parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}')
            }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-time"
            @click="handleUser(scope.row)"
            v-hasPermi="['condition:ours:user']"
          >查看参会人员
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listOurs} from "@/api/condition/ours"

export default {
  name: "Ours",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会议表格数据
      oursList: [],
      // 时间范围查询
      daterangeScheduleTime: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        meetingName: null,
        startTime: null,
        startDate: null,
      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询会议列表 */
    getList() {
      this.loading = true
      if (this.daterangeScheduleTime != null && this.daterangeScheduleTime != '') {
        this.queryParams.beginScheduleTime = this.daterangeScheduleTime[0]
        this.queryParams.endScheduleTime = this.daterangeScheduleTime[1]
      }
      listOurs(this.queryParams).then(response => {
        this.oursList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 表单重置
    reset() {
      this.form = {
        inviterId: null,
        userId: null,
        meetingName: null,
        startTime: null,
        startDate: null,
        password: null,
        id: null,
        state: null,
        reason: null,
        meetingLaunchDate: null,
        isAttendance: null,
        attendanceTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('condition/ours/export', {
        ...this.queryParams
      }, `ours_${new Date().getTime()}.xlsx`)
    },
    /** 查看参会人员情况*/
    handleUser(row) {
      this.$router.push({
        name: 'Detailed',
        params: {meetingName: row.meetingName}
      })
    }
  }
}
</script>
